home *** CD-ROM | disk | FTP | other *** search
- /*
- * xrg.c
- *
- * Practical Algorithms for Image Analysis
- *
- * Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
- */
-
- /*
- * XRG (Region Growing)
- *
- * Program to take a binary image file of regions
- * along with a list of interior points for each
- * region and calculate the area of each region
- * by pixel filling using the interior point as
- * the starting point
- */
-
- #include "xrg.h"
-
-
- #define ON 1
- #define OFF 0
-
- /*
- * global variables
- */
- extern char *optarg;
- extern int optind, opterr;
- extern short tiffInput; /* flag=0 if no ImageIn to set tags; else =1 */
-
-
- /*
- * usage of routine
- */
- void
- usage (char *progname)
- {
- progname = last_bs (progname);
- printf ("USAGE: %s inimg point_file [-L]\n", progname);
- printf ("\n%s calculates the area of each region in a binary image\n", progname);
- printf ("by pixel filling using an interior point as\n");
- printf ("the starting point.\n\n");
- printf ("ARGUMENTS:\n");
- printf (" inimg: input image filename (TIF)\n");
- printf (" point_file: list of centroid coordinates\n");
- printf (" as generated by spp (.vin)\n\n");
- printf ("OPTIONS:\n");
- printf (" -L: print Software License for this module\n");
- exit (1);
- }
-
- void
- main (int argc, char *argv[])
- {
- Image *imgIn;
-
- int i_arg;
- char *vin_file;
- FILE *fpIn;
- float xmin, xmax, ymin, ymax;
- int nsites;
- float fx, fy;
- int x, y;
- long n_pix;
- int i;
-
- /*
- * cmd line options
- */
- static char *optstring = "L";
-
-
- /*
- * parse command line
- */
- optind = 3; /* set getopt to point to the 3rd arg */
- opterr = ON; /* give error messages */
-
-
- if (argc < 3)
- usage (argv[0]);
-
- while ((i_arg = getopt (argc, argv, optstring)) != EOF) {
- switch (i_arg) {
- case 'L':
- print_sos_lic ();
- exit (0);
- default:
- printf ("\ngetopt: unknown condition encountered\n");
- exit (1);
- break;
- }
- }
-
- /*
- * Read input image
- */
- imgIn = ImageIn (argv[1]);
-
- if (imgIn->bps == 8 && imgIn->spp == 3) {
- printf ("Got RGB image!!!\nInput image must be Grayscale or B&W!!\n");
- exit (1);
- }
-
- /*
- * Draw a 255 border around image to eliminate
- * edge effects for line fills
- */
- draw_rect (0, 0, imgIn->width - 1, imgIn->height - 1, imgIn, WHITE);
-
- vin_file = argv[2];
-
- printf ("read data from file %s\n", vin_file);
- /* get size of data set from file */
- if ((fpIn = fopen (vin_file, "r")) == NULL) {
- printf ("\n...cannot open input file %s\n", vin_file);
- exit (1);
- }
- if (fscanf (fpIn, "%d %f %f %f %f", &nsites, &xmin, &xmax, &ymin, &ymax) != 5) {
- printf ("Format error in %s\n", vin_file);
- fclose (fpIn);
- exit (1);
- }
-
- for (i = 0; i < nsites; i++) {
- if (fscanf (fpIn, "%f %f", &fx, &fy) != 2) {
- printf ("Format error in %s\n", vin_file);
- fclose (fpIn);
- exit (1);
- }
- x = (int) fx;
- y = (int) fy;
- n_pix = gdImageFill (x, y, imgIn, WHITE);
- printf ("Area filled for point at (%d, %d) = %ld\n", x, y, n_pix);
- }
-
- fclose (fpIn);
- }
-